﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication1.ConfigCmd
{
    public partial class FormPhoneConfig : Form
    {
        private string devId;
        private string monitorId;
        private string monitorId_Name;

        public FormPhoneConfig(string deviceId, string MonitorDev_Id, string monitorDevId_Name)
        {
            InitializeComponent();

            devId = deviceId;
            monitorId = MonitorDev_Id;
            monitorId_Name = monitorDevId_Name;
        }

        private void FormPhoneConfig_Load(object sender, EventArgs e)
        {
            try
            {
                // 获取手机号
                IEnumerable<tb_mobileNum> qPhone =
                from num in Monitor_DB.instance.db.tb_mobileNum
                select num;

                foreach (var item in qPhone)
                {
                    comboBox1.Items.Add(item.Mobile_num.ToString());
                }

                comboBox1.SelectedIndex = 0;

                textBox1.Text = monitorId_Name;
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message, "错误！", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string detail = "监控箱设备号: " + textBox1.Text + ";  " + "下发手机号: " + comboBox1.Text + ";";
                if (ConfigCmd.configCommand.instance.SetDeivicePhoneNum(textBox1.Text, comboBox1.Text))
                {
                    UserLog.adduseroperlog(User.UserID, User.Username, "指定手机号码", "成功", textBox1.Text, devId, detail);
                    MessageBox.Show("已进入发送队列！", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    UserLog.adduseroperlog(User.UserID, User.Username, "指定手机号码", "失败", textBox1.Text, devId, detail);
                    MessageBox.Show("发送失败!", "", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                this.Dispose();
            }
            catch (Exception Ex)
            {
                MessageBox.Show(Ex.Message, "错误！", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
